﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IRProject.Model
{
    class OrNode : Node
    {
        public override List<ResultData> GetResult()
        {
            List<ResultData> resultlist = new List<ResultData>();
            foreach (Node n in Children)
            {
                List<ResultData> temp = n.GetResult();
                foreach (ResultData r in temp)
                {
                    operate(r, resultlist);
                }

            }
            return resultlist;
        }

        void operate(ResultData data, List<ResultData> result)
        {
            if (!result.contain(data.DocId))
            {
                result.Add(data);
            }
            else
            {
                ResultData rd = result.getById(data.DocId);
                if (data.Similarity >= rd.Similarity)
                {
                    result.Remove(rd);
                    result.Add(data);
                }
            }
        }

    }
}
